home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0799 / 705 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  4.0 KB

  1. From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  2. Date: Wed, 15 Dec 93 11:08:59 +0100
  3. Message-Id: <9312151008.AA18526@issan.informatik.uni-dortmund.de>
  4. To: mint@atari.archive.umich.edu
  5. Subject: MiNT 1.09/MinixFS 0.6pl9: FIONREAD broken
  6.  
  7. FIONREAD always returns 1 on tosfs and minixfs.  On the pipefs,
  8. FIONREAD returns -1 if there are no writers, and FIONWRITE returns -1
  9. if there are no readers.  This breaks cat from textutils 1.9.
  10. FIONREAD should always return 0 on eof.  The patch fixes this.
  11.  
  12. ************************* MiNT 1.09 *************************
  13. --- orig/pipefs.c    Fri Jun 25 22:20:54 1993
  14. +++ pipefs.c    Tue Dec 14 22:50:10 1993
  15. @@ -747,12 +747,13 @@
  16.  
  17.      this = (struct fifo *)f->fc.index;
  18.  
  19. -    if (mode == FIONREAD) {
  20. +    switch (mode) {
  21. +    case FIONREAD:
  22.              p = (f->flags & O_HEAD) ? this->outp : this->inp;
  23.              assert(p != 0);
  24.              if (p->writers <= 0 || p->writers == VIRGIN_PIPE) {
  25.                  DEBUG(("pipe FIONREAD: no writers"));
  26. -                r = -1;
  27. +                r = 0;
  28.              } else {
  29.                  r = p->tail - p->head;
  30.                  if (r < 0) r += PIPESIZ;
  31. @@ -760,12 +761,12 @@
  32.                      r = r >> 2;    /* r /= 4 */
  33.              }
  34.              *((long *) buf) = r;
  35. -    }
  36. -    else if (mode == FIONWRITE) {
  37. +            break;
  38. +    case FIONWRITE:
  39.              p = (f->flags & O_HEAD) ? this->inp : this->outp;
  40.              assert(p != 0);
  41.              if (p->readers <= 0) {
  42. -                r = -1;
  43. +                r = 0;
  44.              } else {
  45.                  r = p->tail - p->head;
  46.                  if (r < 0) r += PIPESIZ;
  47. @@ -774,8 +775,9 @@
  48.                      r = r >> 2;    /* r /= 4 */
  49.              }
  50.              *((long *) buf) = r;
  51. -    }
  52. -    else if (mode == F_SETLK || mode == F_SETLKW) {
  53. +            break;
  54. +    case F_SETLK:
  55. +    case F_SETLKW:
  56.          lck = (struct flock *)buf;
  57.          while (this->flags & O_LOCK) {
  58.              if (this->lockpid != curproc->pid) {
  59. @@ -803,8 +805,8 @@
  60.              this->lockpid = curproc->pid;
  61.              f->flags |= O_LOCK;
  62.          }
  63. -    }
  64. -    else if (mode == F_GETLK) {
  65. +        break;
  66. +    case F_GETLK:
  67.          lck = (struct flock *)buf;
  68.          if (this->flags & O_LOCK) {
  69.              lck->l_type = F_WRLCK;
  70. @@ -813,8 +815,8 @@
  71.          }
  72.          else
  73.              lck->l_type = F_UNLCK;
  74. -    }
  75. -    else if (mode == TIOCFLUSH) {
  76. +        break;
  77. +    case TIOCFLUSH:
  78.          if (this->inp) {
  79.              this->inp->head = this->inp->tail;
  80.              wake(IO_Q, (long)this->inp);
  81. @@ -823,11 +825,20 @@
  82.              this->outp->head = this->outp->tail;
  83.              wake(IO_Q, (long)this->outp);
  84.          }
  85. -    } else if (mode == TIOCIBAUD || mode == TIOCOBAUD) {
  86. +        break;
  87. +    case TIOCIBAUD:
  88. +    case TIOCOBAUD:
  89.          *(long *)buf = -1L;
  90. -    } else if (mode == TIOCGFLAGS) {
  91. +        break;
  92. +    case TIOCGFLAGS:
  93.          *((unsigned short *)buf) = 0;
  94. -    } else if (mode >= TCURSOFF && mode <= TCURSGRATE) {
  95. +        break;
  96. +    case TCURSOFF:
  97. +    case TCURSON:
  98. +    case TCURSSRATE:
  99. +    case TCURSBLINK:
  100. +    case TCURSSTEADY:
  101. +    case TCURSGRATE:
  102.      /* kludge: this assumes TOSWIN style escape sequences */
  103.          tty_putchar(f, (long)'\033', RAW);
  104.          switch (mode) {
  105. @@ -851,7 +862,8 @@
  106.          case TCURSGRATE:
  107.              return this->cursrate;
  108.          }
  109. -    } else {
  110. +        break;
  111. +    default:
  112.      /* if the file is a terminal, Fcntl will automatically
  113.       * call tty_ioctl for us to handle 'generic' terminal
  114.       * functions
  115. --- orig/tosfs.c    Fri Jun 25 22:24:32 1993
  116. +++ ./tosfs.c    Sat Nov 20 02:34:14 1993
  117. @@ -1147,9 +1147,17 @@
  118.      extern int flk;        /* set in main.c if _FLK already installed */
  119.  
  120. -    if (mode == FIONREAD || mode == FIONWRITE) {
  121. +    switch (mode) {
  122. +    case FIONREAD:
  123. +        r = Fseek (0L, (int) f->devinfo, 1);
  124. +        if (r < 0) return r;
  125. +        *(long *) buf = Fseek (0L, (int) f->devinfo, 2) - r;
  126. +        (void) Fseek (r, (int) f->devinfo, 0);
  127. +        return 0;
  128. +    case FIONWRITE:
  129.          *((long *)buf) = 1;
  130.          return 0;
  131. -    }
  132. -    else if (mode == F_SETLK || mode == F_SETLKW || mode == F_GETLK) {
  133. +    case F_SETLK:
  134. +    case F_SETLKW:
  135. +    case F_GETLK:
  136.          fl = ((struct flock *)buf);
  137.          t.l = *fl;
  138. ************************* MinixFS 0.6pl9 *************************
  139. --- orig/minixfs/minixdev.c    Sat Nov 27 19:42:24 1993
  140. +++ ./minixfs/minixdev.c    Tue Dec 14 19:37:26 1993
  141. @@ -445,7 +445,18 @@
  142.      switch (mode)
  143.        {
  144.        case FIONREAD:
  145. +    {
  146. +      d_inode rip;
  147. +      long nread;
  148. +      read_inode (f->fc.index, &rip, f->fc.dev);
  149. +      nread = rip.i_size - f->pos;
  150. +      if (nread < 0)
  151. +        nread = 0;
  152. +      *(long *) buf = nread;
  153. +      return 0;
  154. +    }
  155. +
  156.        case FIONWRITE:
  157.      {
  158.